 fn GetVectorsAngle v1 v2 =
(
theAngle = acos(dot (normalize v1) (normalize v2))
)

wallThickness = 0.75
boxThickness = 0.5
fudgeFactor = 0.3 --mm
sideLength = 25.0 


legSide = 3.1 --adding fudge
legOverhangFudge = 0.31 --amount to add to account for sagging due to overhang
legCenterDistance = 5.2 --distance from leg to center of object
legLength = sqrt(sideLength*sideLength +sideLength*sideLength)*1.10
centerHoleRadius = 4.5

topBoxSpacing = 2 --top cut outs will result in window frame pattern, how thick should window frame be
bottomTriSide1 = 6.4

bottomTriAdjustment = 0.5

bottomTriSide2 = 6.5
bottomTriSide3 = sqrt(bottomTriSide2*bottomTriSide2 + bottomTriSide1*bottomTriSide1)

screwMountHeight = 1.6
screwMountRadius = 1.12 + 0.1 --0.1 is fudge
screwDiameter = (1.2 + 0.3)
screwSeparation = 21.0 --mm

boxheight = wallThickness*2 + legSide + legOverhangFudge --mm, front plate is now short.

--camera mount Variables
cameraMountScrewRadius = (screwDiameter/2)
cameraMountScrewHoleDepth = 5.0
cameraMountSupportRadius = 2.0
cameraMountOfffset = 7.0
cameraMountSeparation = screwSeparation

--battery Post variables

batteryPostRadiusfudge = 0.5 -- allow adjustment to let posts slide in
batteryPostRadius = 1.0
batteryPostHoleRadius = batteryPostRadius + batteryPostRadiusfudge

batterySupportRadius = batteryPostHoleRadius + 0.5
batteryPostXOffset = sideLength/2.0 + batteryPostHoleRadius
batteryPostYOffset = bottomTriSide3

--create battery holder
batteryHolderHeight = 8
batteryPlateThickness = 0.5
batteryCrossBraceWidth = 1.0
batteryWidth = 21.0 --actual battery width
batteryHeight = 7.75 --actual battery height


--Starting Z positions
--easier to define all the heights in the figure than to do calculations within functions
legZ = wallThickness*2
cameraMountZ = boxHeight
cameraMountHoleZ = (wallThickness*2+legSide)
bottomTriZ = -wallThickness
centerHoleZ = -wallThickness

fn createLegs someObject =
(
		legOutline1 = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:legLength width:(legSide+2*wallThickness) height:(legSide + 2*wallThickness + legOverhangFudge) mapcoords:on pos:[0,0,0] isSelected:on 		
		legOutline2 = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:legLength width:(legSide+2*wallThickness) height:(legSide + 2*wallThickness + legOverhangFudge) mapcoords:on pos:[0,0,0] isSelected:on 			
		leg1 = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:legLength width:(legSide+2*wallThickness) height:(legSide + 2*wallThickness + legOverhangFudge) mapcoords:on pos:[0,0,0] isSelected:on 	
		leg2 = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:legLength width:(legSide+2*wallThickness) height:(legSide + 2*wallThickness + legOverhangFudge) mapcoords:on pos:[0,0,0] isSelected:on 		
		legInside1 = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:legLength width:legSide height:(legSide + legOverhangFudge) mapcoords:on pos:[0,0,wallThickness] isSelected:on 		
		legInside2 = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:legLength width:legSide height:(legSide + legOverhangFudge) mapcoords:on pos:[0,0,wallThickness] isSelected:on 			
		rotate leg1 (angleaxis 45 [0,0,1])
		rotate legOutline1 (angleaxis 45 [0,0,1])
		rotate legInside1 (angleaxis 45 [0,0,1])
		rotate leg2 (angleaxis -45 [0,0,1])
		rotate legOutline2 (angleaxis -45 [0,0,1])	
		rotate legInside2 (angleaxis -45 [0,0,1])

		ProBoolean.CreateBooleanObject leg1 leg2 0 0 1
		ProBoolean.CreateBooleanObject leg1 legInside1 2 0 1
		ProBoolean.CreateBooleanObject leg1 legInside2 2 0 1	
		ProBoolean.CreateBooleanObject someObject legOutline1 2 0 1 --remove shape of leg from box
		ProBoolean.CreateBooleanObject someObject legOutline2 2 0 1 --remove shape of leg from box		
)


 


fn createScrewMount x y someObject =
(
mount1 = Tube smooth:on sides:25 capsegs:1 heightsegs:1 radius1:screwMountRadius radius2:(screwDiameter/2) height:(screwMountHeight + wallThickness*0.5) mapcoords:on pos:[screwSeparation/2*x,screwSeparation/2*y,boxHeight] isSelected:on
hole1 = Cylinder smooth:on heightsegs:1 capsegs:1 sides:25 height:(screwMountHeight*2) radius:(screwDiameter/2) mapcoords:on pos:[screwSeparation/2*x,screwSeparation/2*y,(boxHeight-wallThickness)] isSelected:on	
ProBoolean.CreateBooleanObject someObject mount1 0 0 1	
ProBoolean.CreateBooleanObject someObject hole1 2 0 1		
)

fn createBatteryMount x y someObject=
(
mount1 = Tube smooth:on sides:25 capsegs:1 heightsegs:1 radius1:batterySupportRadius  radius2:batteryPostHoleRadius height:(boxHeight/2) mapcoords:on pos:[batteryPostXOffset*x,batteryPostYOffset*y,0] isSelected:on
ProBoolean.CreateBooleanObject someObject mount1 0 0 1	
)
 
 fn addCameraMount someObject=
 (
support1 = Cylinder smooth:on sides:18 capsegs:1 heightsegs:5  radius:cameraMountSupportRadius height:cameraMountOfffset mapcoords:on transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [cameraMountSeparation/2,sideLength/2+cameraMountOfffset,cameraMountSupportRadius]) isSelected:on
support2 = Cylinder smooth:on sides:18 capsegs:1 heightsegs:5 radius:cameraMountSupportRadius height:cameraMountOfffset mapcoords:on transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [-cameraMountSeparation/2,sideLength/2+cameraMountOfffset,cameraMountSupportRadius]) isSelected:on
hole1 = Cylinder smooth:on sides:18 capsegs:1 heightsegs:5  radius:cameraMountScrewRadius height:cameraMountScrewHoleDepth mapcoords:on transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [cameraMountSeparation/2,sideLength/2+cameraMountOfffset,cameraMountSupportRadius]) isSelected:on
hole2 = Cylinder smooth:on sides:18 capsegs:1 heightsegs:5 radius:cameraMountScrewRadius height:cameraMountScrewHoleDepth mapcoords:on transform:(matrix3 [1,0,0] [0,0,1] [0,-1,0] [-cameraMountSeparation/2,sideLength/2+cameraMountOfffset,cameraMountSupportRadius]) isSelected:on	 
ProBoolean.CreateBooleanObject support1 hole1 2 0 1	
ProBoolean.CreateBooleanObject support2 hole2 2 0 1
ProBoolean.CreateBooleanObject someObject support1 0 0 1	 
ProBoolean.CreateBooleanObject someObject support2 0 0 1	 	 
 )	 
 
 fn createBatteryPost x y someObject =
(
mount1 = Cylinder smooth:on sides:25 capsegs:1 heightsegs:1 radius:(batteryPostRadius - batteryPostRadiusfudge) height:(boxHeight/2.0 + batteryHolderHeight) mapcoords:on pos:[batteryPostXOffset*x,batteryPostYOffset*y,0] isSelected:on
mount2 = Cylinder smooth:on sides:25 capsegs:1 heightsegs:1 radius:(batteryPostRadius - batteryPostRadiusfudge) height:(batteryHeight/2.0) mapcoords:on pos:[batteryWidth/2*x,batteryPostYOffset*y,0] isSelected:on	
ProBoolean.CreateBooleanObject someObject mount1 0 0 1	
ProBoolean.CreateBooleanObject someObject mount2 0 0 1	
)
 
 fn createBatteryPlate =
 (
	batteryPlate =  Box lengthsegs:1 widthsegs:1 heightsegs:1 length:(batteryPostYOffset*2 + batteryPostRadius*2)  width:(batteryPostXOffset*2 + batteryPostRadius*2) height:(batteryPlateThickness) mapcoords:on pos:[0,0,0] isSelected:on 	 
	batteryPlateInside =  Box lengthsegs:1 widthsegs:1 heightsegs:1 length:(batteryPostYOffset*2 - batteryPostRadius*2)  width:(batteryPostXOffset*2 - batteryPostRadius*2) height:(batteryPlateThickness) mapcoords:on pos:[0,0,0] isSelected:on 	  	 
 	ProBoolean.CreateBooleanObject batteryPlate batteryPlateInside 2 0 1	 
		
	
 	createBatteryPost 1 1 batteryPlate
	createBatteryPost -1 1 batteryPlate
	createBatteryPost -1 -1 batteryPlate
	createBatteryPost 1 -1 batteryPlate			
 	batteryPlate.pos.x += sideLength + batterySupportRadius*4 
 )
createBatteryPlate()

base  = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:sideLength width:sideLength height:(boxheight) mapcoords:on pos:[0,0,0] isSelected:on 
insidebase  = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:(sideLength-boxThickness) width:(sideLength-boxThickness) height:(boxheight) mapcoords:on pos:[0,0,0] isSelected:on 
ProBoolean.CreateBooleanObject base insidebase 2 0 1	  
addCameraMount base
 
select base
createLegs base

	  
ProBoolean.CreateBooleanObject base leg1 0 0 1
 
 
createScrewMount 1 1 base
createScrewMount -1 1 base
createScrewMount -1 -1 base
createScrewMount 1 -1 base

createBatteryMount 1 1 base
createBatteryMount -1 1 base
createBatteryMount -1 -1 base
createBatteryMount 1 -1 base


